/*
 * Copyright (c) 2017, hehanpeng 何汉鹏 (hehanpeng@csii.com.com).
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.hehanpeng.springbootnetty.java8583.quickstart;

import com.hehanpeng.springbootnetty.java8583.core.Iso8583MessageCibFactory;
import com.hehanpeng.springbootnetty.java8583.field.Iso8583DataCibHeader;
import com.hehanpeng.springbootnetty.java8583.field.Iso8583FieldType;
import com.hehanpeng.springbootnetty.java8583.field.Iso8583FillBlankStrategy;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.nio.charset.Charset;

/**
 * 封装消息格式的工厂类</br>
 * 提供静态工厂方法，但每次都会new对象，所以，建议开发对生成的对象做缓存操作
 *
 * @author hehanpeng@csii.com.com
 * @ClassName: BankFactory
 * @Description: 用于封装消息格式的工厂类
 * @date 2017年3月24日 上午10:52:38
 */
@Configuration
class QuickStartFactory {

    /**
     * 供熟悉框架使用的factory
     *
     * @return Iso8583MessageFactory
     * @Title: forQuickStart
     * @Description: 供熟悉框架使用的factory
     * @author hehanpeng@csii.com.com
     * @date 2017年8月3日 下午4:30:29
     */
    public static Iso8583MessageCibFactory forQuickStart() {
        Iso8583DataCibHeader dataHeaderType = new Iso8583DataCibHeader(
                new Iso8583FieldType(Iso8583FieldType.FieldTypeValue.CHAR, 4),
                new Iso8583FieldType(Iso8583FieldType.FieldTypeValue.CHAR, 32));
        Iso8583MessageCibFactory factory = new Iso8583MessageCibFactory(4, true, Charset.forName("UTF-8"), dataHeaderType);
        factory.set(3, new Iso8583FieldType(Iso8583FieldType.FieldTypeValue.CHAR, 6,"a_3"))
                .set(4, new Iso8583FieldType(Iso8583FieldType.FieldTypeValue.CHAR, 12, "a_4").setFillBlankStrategy(Iso8583FillBlankStrategy.leftAppendStrategy('0', true)))
                .set(7, new Iso8583FieldType(Iso8583FieldType.FieldTypeValue.CHAR, 10, "a_7"))
                .set(11, new Iso8583FieldType(Iso8583FieldType.FieldTypeValue.CHAR, 6, "a_11"))
                .set(12, new Iso8583FieldType(Iso8583FieldType.FieldTypeValue.CHAR, 6, "a_12"))
                .set(32, new Iso8583FieldType(Iso8583FieldType.FieldTypeValue.LLVAR_CHAR, 0, "a_32"))
                .set(70, new Iso8583FieldType(Iso8583FieldType.FieldTypeValue.CHAR, 3, "a_70"))
                .set(100, new Iso8583FieldType(Iso8583FieldType.FieldTypeValue.LLVAR_CHAR, 0, "a_100"));
        return factory;
    }

    @Bean
    Iso8583MessageCibFactory iso8583MessageCibFactory() {
        Iso8583MessageCibFactory iso8583MessageCibFactory = forQuickStart();
        return iso8583MessageCibFactory;
    }
}
